package com.jzr.common.util;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

public class QueryUtil {
    public static QueryWrapper<?> orderBy(QueryWrapper<?> qw, String orderByCause){
        if(orderByCause == null) return qw;

        String[] a1 = orderByCause.split(",");
        for(String e : a1){
            String[] a2 = e.split(" ");
            if(a2.length>0){
                if(a2.length>1){
                    String type = a2[1].trim();
                    if(type.equalsIgnoreCase("asc")){
                        qw.orderByAsc(a2[0]);
                    }else{
                        qw.orderByDesc(a2[0]);
                    }
                }else{
                    qw.orderByAsc(a2[0]);
                }
            }
        }
        return qw;
    }
}
